package com.opo5.logisticsmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opo5.logisticsmanagement.common.R;
import com.opo5.logisticsmanagement.domain.PlanList;
import com.opo5.logisticsmanagement.domain.SparePlan;
import com.opo5.logisticsmanagement.service.SparePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("spareplan")
public class SparePlanController {
    @Autowired
    private SparePlanService sparePlanService;

    /**
     *
     * @param sparePlan
     * @return
     */
    @PostMapping
    public R save(@RequestBody SparePlan sparePlan){
        sparePlanService.save(sparePlan);
        return R.success("添加成功");
    }

    /**
     *
     * @param currentPage
     * @param pageSize
     * @param sparePlan
     * @return
     */
    @GetMapping("/{currentPage}/{pageSize}")
    public R getAll(@PathVariable int currentPage,@PathVariable int pageSize,SparePlan sparePlan){
        IPage<SparePlan> page = sparePlanService.selectPage(currentPage, pageSize, sparePlan);
        return R.success(page);
    }

    /**
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R delList(@PathVariable int id){
        sparePlanService.removeById(id);
        return R.success("删除成功");
    }

    /**
     *
     * @param sparePlan
     * @return
     */
    @PutMapping
    public R putList(@RequestBody SparePlan sparePlan){
        sparePlanService.updateById(sparePlan);
        return R.success("修改成功");
    }
}
